package cn.hx.controller.system;

import cn.hx.entity.UserInfo;
import cn.hx.service.UserInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

@Controller
public class UserController {
    @Resource
    UserInfoService userInfoService;


    @GetMapping("system/user/userList")
    public String userLists(
            ModelMap modelMap,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "5") int size,
           UserInfo userInfo) {
        modelMap.addAttribute("userPage",userInfoService.page(page, size));
        return "system/user/userList";
    }
    @GetMapping("system/user/updateUser/{id}")
    public String update(@PathVariable Integer id,ModelMap map){
        map.addAttribute("user",userInfoService.queryById(id));
        return "system/user/updateUser";
    }
    @PostMapping("system/user/update/{id}")
    public String updateSubmit(UserInfo userInfo){
        System.out.println(userInfo.getRole().getId());
        userInfoService.update(userInfo);
        return "redirect:/system/user/userList";
    }
    @GetMapping("ResetPassword/{id}")
    public String updatePassword(@PathVariable Integer id){
        UserInfo userInfo=new UserInfo();
        userInfo.setId(id);
        userInfo.setPassword("61bd60c60d9fb60cc8fc7767669d40a1");
        userInfoService.update(userInfo);
        return   "redirect:/system/user/userList";
    }
}
